﻿Public Class frmListFormula
    Dim dbBase As New dbFormula
    Dim Var As New varDeclare
    Dim dsBase As DataSet
    Dim EntryID As String
    Dim frmCtrl As New FormControl

    Private Sub frmListFormula_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        EntryID = ""
        dsBase = dbBase.FormulaList(Var.CompID)
        ToolbarHeader1.Iniliaze("LIST : Formula", Me, Nothing, GridAndFind1.getDataGridView(), "ID")
        GridAndFind1.Initialize(dsBase, "ID", ToolbarHeader1, Me, True)
        If (dsBase IsNot Nothing) Then
            GridAndFind1.getDataGridView().Columns("ID").Visible = False
            GridAndFind1.getDataGridView().Columns("Tipe").Visible = False
            GridAndFind1.getDataGridView().Columns("Formula Date").DefaultCellStyle.Format = "dd MMM yyyy"
            GridAndFind1.getDataGridView().Columns("Qty").DefaultCellStyle.FormatProvider = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
            GridAndFind1.getDataGridView().Columns("Qty").DefaultCellStyle.Format = "N0"
            GridAndFind1.getDataGridView().Columns("Qty").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            GridAndFind1.getDataGridView().Columns("Amount/Qty").DefaultCellStyle.FormatProvider = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
            GridAndFind1.getDataGridView().Columns("Amount/Qty").DefaultCellStyle.Format = "N2"
            GridAndFind1.getDataGridView().Columns("Amount/Qty").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        End If
    End Sub

    Private Sub tsNew_Click(ByVal sender As ToolbarHeader) Handles ToolbarHeader1.tsNewClick
        Dim OpenForm As New frmEntryFormula
        OpenForm.EntryID = ""
        frmCtrl.OpenFormDetail(Me, OpenForm)
    End Sub

    Private Sub GridCellEnter_Click(ByVal sender As GridAndFind, KeyValue As String) Handles GridAndFind1.GridCellEnter
        Dim dvFind As DataView = New DataView(dsBase.Tables(0))
        dvFind.RowFilter = "[ID] = '" & KeyValue & "'"
        EntryID = dvFind.Item(0).Row("ID").ToString()
    End Sub

    Private Sub tsEdit_Click(ByVal sender As ToolbarHeader) Handles ToolbarHeader1.tsEditClick
        Dim OpenForm As New frmEntryFormula
        OpenForm.EntryID = EntryID
        frmCtrl.OpenFormDetail(Me, OpenForm)
    End Sub

    Private Sub tsDelete_Click(ByVal sender As ToolbarHeader) Handles ToolbarHeader1.tsDeleteClick
        If (EntryID.Trim() <> "") Then
            Dim result As Boolean = dbBase.deleteFormula(EntryID, Var.CompID)
            If (result) Then
                frmCtrl.openChild(New frmListFormula, Me.ParentForm)
            Else : MessageBox.Show("Error in Delete Progress")
            End If
        Else : MessageBox.Show("Please Choose User First")
        End If
    End Sub

    Private Sub tsPrint_Click(ByVal sender As ToolbarHeader) Handles ToolbarHeader1.tsPrintClick
        ''Event 
    End Sub

    Private Sub tsRefresh_Click(ByVal sender As ToolbarHeader) Handles ToolbarHeader1.tsRefreshClick
        frmCtrl.openChild(New frmListFormula, Me.ParentForm)
    End Sub
End Class